﻿
@{
    Layout = null;
    var returnUrl = Request.QueryString["returnUrl"];
    if (!string.IsNullOrEmpty(returnUrl)) {
        returnUrl = System.Web.HttpUtility.UrlDecode(returnUrl);
    }
}
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>注册</title>
    <meta name="viewport" content="width=device-width,initial-scale=1.0, minimum-scale=1.0,maximum-scale=1.0, user-scalable=no" />
    <link href="~/Content/css/base.css" rel="stylesheet" />
    <link rel="stylesheet" href="~/Content/css/tuoken.css" />
    <script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
    <script type="text/javascript" src="~/Content/js/base.js"></script>
    <script src="~/Content/js/layer/1.9.3/layer.js"></script>
</head>

<body>

    <div class="property">
        <div class="regBox">
            <div class="mod-forms">
                <div class="ui-item border-bottom">
                    <div class="phoneSelect relative phoneBox">
                        <i class="jiao_down absolute"></i>
                        <select class="fn-left mobile_code">
                            <option>+86</option>
                            <option>+886</option>
                        </select>
                    </div>
                    <div class="hidden">
                        <input class="ui-input" type="number" id="phone" placeholder="输入手机号">
                    </div>
                </div>
                <div class="ui-item border-bottom">
                    <div class="hidden">
                        <input class="ui-input pwd" type="password" placeholder="新密码">
                    </div>
                </div>
                <div class="ui-item border-bottom">
                    <div class="hidden">
                        <input class="ui-input r_pwd" type="password" placeholder="确认密码">
                    </div>
                </div>
                <div class="ui-item border-bottom relative">
                    <input class="ui-input" type="text" id="yzm" placeholder="短信验证码">
                    <input type="hidden" name="token" value="" id="token" />
                    <input type="button" class="yzm absolute" value="获取验证码">
                </div>
            </div>
        </div>
        <a href="javascript:void(0)" class="ui-btn-auto on submit">确认提交</a>
    </div>
    <div id="popup"></div>
    <script src="https://cdn.dingxiang-inc.com/ctu-group/captcha-ui/index.js"></script>
    <script type="text/javascript">
        var myCaptcha;
        $(function () {
            myCaptcha = _dx.Captcha(document.getElementById('popup'), {
                appId: 'd857f517ea59f9c229a76b88aa938719',
                style: 'popup',
                success: function (token) {
                    $("#token").val(token);
                    myCaptcha.hide();
                    sendsms();
                }
            })
            var flag = false;
            $('.submit').click(function () {
                var mobile = $("#phone").val();
                var password = $(".pwd").val();
                var re_password = $(".r_pwd").val();
                var code = $("#yzm").val();
                if (mobile.length <= 0) {
                    layer.msg("手机号码不能为空");
                    return;
                }
                if (password.length < 6 || password.length > 16) {
                    layer.msg("新密码长度必须在6到16位");
                    return;
                }
                if (!/^(?![^a-zA-Z]+$)(?!\D+$)/.test(password)) {
                    layer.msg("新密码必须包含数字和字符");
                    return;
                }
                if (re_password.length <= 0) {
                    layer.msg("请输入确认密码");
                    return;
                }
                if (password != re_password) {
                    layer.msg("两次密码输入不一致");
                    return;
                }
                if (code.length <= 0) {
                    layer.msg("请输入验证码");
                    return;
                }
                if (flag) return;
                flag = true;
                $.ajax({
                    //几个参数需要注意一下
                    type: "POST",//方法类型
                    dataType: "json",//预期服务器返回的数据类型
                    url: "/Home/ForgetPwd",//url
                    data: { mobile: mobile, code: code, password: password, re_password: re_password },
                    success: function (result) {
                        if (result.result_code == 1000) {
                            layer.msg("重置密码成功");
                            setTimeout("window.location.href = '/home/login'+ '@Html.Raw((!string.IsNullOrEmpty(returnUrl) ? "?returnUrl=" + System.Web.HttpUtility.UrlEncode(returnUrl) : ""))'", 1500);
                        } else {
                            layer.msg(result.result_msg);
                        }
                        flag = false;
                    },
                    error: function () {
                        layer.msg("异常！");
                        flag = false;
                    }
                });
            });
        });
        function sendsms() {
            $.ajax({
                //几个参数需要注意一下
                type: "POST",//方法类型
                dataType: "json",//预期服务器返回的数据类型
                url: "/Home/GetCode",//url
                data: { mobile: $("#phone").val(), use_type: "token_forget", mobile_code: $(".mobile_code").val().replace("+", ""), code_size: 6, code: $("#token").val()},
                success: function (result) {
                    if (result.result_code == 1000) {
                        layer.msg(result.result_msg);
                        new invokeSettime(".yzm");
                    }
                    else {
                        layer.msg(result.result_msg);
                        new invokeFn(".yzm", fn);
                    }
                },
                error: function () {
                    layer.msg("异常！");
                    new invokeFn(".yzm", fn);
                }
            });
        }
        var fn = function () {
            var mobile = $("#phone").val();
            if (mobile.length == 0) {
                layer.msg("手机号码不能为空"); return;
            }
            var creg = /^(13[0-9]|14[5-9]|15[012356789]|166|17[0-8]|18[0-9]|19[89])[0-9]{8}$/;
            var treg = /^09\d{8}$/;
            if (!(creg.test(mobile) || treg.test(mobile))) {
                layer.msg("请输入正确的手机号");
                return;
            }
            $(".yzm").unbind("click");
            myCaptcha.reload();
            myCaptcha.show()
        }
        $(".yzm").click(fn);
        function invokeSettime(obj) {
            var countdown = 60;
            settime(obj);
            function settime(obj) {
                if (countdown == 0) {
                    $(obj).click(fn);
                    $(obj).val("获取验证码");
                    countdown = 60;
                    return;
                } else {
                    $(obj).unbind("click");
                    $(obj).val("(" + countdown + ") s ");
                    countdown--;
                }
                setTimeout(function () {
                    settime(obj)
                }, 1000)
            }
        }

        function invokeFn(obj, fn) {
            $(obj).click(fn);
        }




    </script>
</body>

</html>